<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
		<meta charset="utf-8">
		<title>登 录</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="${pageContext.request.contextPath}/resource/weixin/css/mui.min.css">
		<style>
			h5 {
				margin: 5px 7px;
			}
			*{
				margin: 0 0;
			}
		</style>
	</head>
<body style="background-color: #ffffff;">
		
		<div><img src="${pageContext.request.contextPath}/resource/weixin/image/niu.png" style="width: 100%;height: auto;" style="margin: 0;"></div>
		<div class="mui-content" style="background-color: #ffffff;">
			<div class="mui-content-padded" style="margin: 0;">
				
				<form class="mui-input-group">
					<div class="mui-input-row">
						<label><span class="mui-icon mui-icon-person" style="color: #007AFF;"> </span></label>
						<input id="phoneNumber" type="text" placeholder="请输入电话号码" class="mui-input-clear">
					</div>
					<div class="mui-input-row">
						<label><span class="mui-icon mui-icon-locked" style="color: #007AFF;"> </span></label>
						<input id="password" type="password" class="mui-input-clear" placeholder="请输入密码">
					</div>

					
					<div class="mui-button-row">
						<button id="loginBtn" onclick="login()" type="button" class="mui-btn mui-btn-primary" style="width: 70%;">确 定</button>&nbsp;&nbsp;
					
					</div>
				</form>
			</div>
			
			<div style="width: 80%;margin-left: 10%;">
			    <p style="font-size: 12px;margin-top: 10px;">
			       			 请确保您的手机号码在物业处已经登记（如果其他住户已登记，您只需要联系该住户在APP中添加您的手机号码即可开通），使用手机号码直接登录，登录默认密码为<span id="num" style="color: #e91360">123456</span>，如需修改密码或体验更丰富功能，请<a style="color: #15b5e9">下载</a>家家牛智慧社区APP。
			    </p></div>
			</div>
		<script src="${pageContext.request.contextPath}/resource/assets/js/jquery-2.0.3.min.js"></script>
	<script src="${pageContext.request.contextPath}/resource/assets/js/jquery.cookie.js"></script>
	<script src="${pageContext.request.contextPath}/resource/weixin/js/mui.min.js"></script>
<script>
var openId = "${openId}";
//var userId ="${user.objectId}";
var returnType= "${returnType}";
//     $(document).ready(function(){
//     	if (openId == "") {
// 			openId = $.cookie("openId");
// 		}
    	
//     	if(openId == null){
//     		mui.toast("服务器错误！！！");
//     	}
		
// 		if (userId != "" || $.cookie("userId") != null) {
// 			mui.toast("您已经登录，无需重复登录！");
// 		}
//     });
    
    function login(){
		var phoneNumber = $("#phoneNumber").val();
		var password = $("#password").val();
		var regx = /^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/;
 		
  	   if(!regx.test(phoneNumber)){
  		 mui.toast("请填写正确的电话号码或者手机号码！");
  		   return;
  	   }
  	   
  	   if($.trim(password) == ""){
  		 mui.toast("请输入密码");
  		   return;
  	   }
		
		$.ajax({
    		url:"login",
    		type:'post',
    		data:{username:phoneNumber,password:password,openId:openId},
    		dataType:'json',
    		success:function(data){
    			if(data == 200){
    				mui.toast("登录成功，请返回微信界面体验一键开门！");
    				if(returnType=="user"){
    					window.location.href="mine";
    				}else if(returnType=="annouce"){
    					window.location.href="announce_list";
    				}else if(returnType=="unlock"){
    					window.location.href="getUnlock";
    				}
    			}else{
    				mui.toast("身份验证失败,用户名或者密码错误！");
    			}
    		},
    		error:function(data){
    			mui.toast("服务器发生错误，请稍后再试！");
    		}
    	});
	}

</script>
	</body>

	
</html>